using System;
using System.Diagnostics;
using System.IO;
using NUnit.Framework;

using BuildAutoIncrement;

namespace TestUnits {
    /// <summary>
    /// Summary description for Class1.
    /// </summary>
    [TestFixture]
    public class ResourceInfoStreamTest {

        private class TestResourceFileStream : ResourceFileStream {
            public TestResourceFileStream(TextReader textReader) {
                m_fileContent = textReader.ReadToEnd();
            }

            public TestResourceFileStream(string content) {
                m_fileContent = content;
            }
        }
	
        public ResourceInfoStreamTest() {
        }

        [SetUp] 
        public void SetUp() {
        }

        [TearDown] 
        public void TearDown() {
        }

        public void TestEntireFilesReading() {
            TestResourceFileStream rfs = new TestResourceFileStream(rc1);
            AssemblyVersions av = rfs.GetVersions();
            Assert.IsTrue(av[AssemblyVersionType.AssemblyVersion] == ProjectVersion.Empty);
            Assert.IsTrue(av[AssemblyVersionType.AssemblyFileVersion].ToString() == "1.2.3.21");
            Assert.IsTrue(av[AssemblyVersionType.AssemblyInformationalVersion].ToString() == "1.2.3.4");
        }

        /*
        public void TestSampleReading() {
            // this is not a valid content
            string content = "  < Assembly: AssemblyVersion(  \"1.3.0.13\"  ) >  \n";
            TestAssemblyInfoStream ais = new TestAssemblyInfoStream(content, "AssemblyInfo.vb");
            AssemblyVersions av = ais.GetVersions();
            Assert.IsTrue(av[AssemblyVersionType.AssemblyVersion] == ProjectVersion.Empty);
            Assert.IsTrue(av[AssemblyVersionType.AssemblyFileVersion] == ProjectVersion.Empty);
            Assert.IsTrue(av[AssemblyVersionType.AssemblyInformationalVersion] == ProjectVersion.Empty);

            // this is not a valid content
            content = "< Assembly: AssemblyVersion(  \"1.3.0.13\"  ) >  \n";
            ais = new TestAssemblyInfoStream(content, "AssemblyInfo.vb");
            av = ais.GetVersions();
            Assert.IsTrue(av[AssemblyVersionType.AssemblyVersion] == ProjectVersion.Empty);
            Assert.IsTrue(av[AssemblyVersionType.AssemblyFileVersion] == ProjectVersion.Empty);
            Assert.IsTrue(av[AssemblyVersionType.AssemblyInformationalVersion] == ProjectVersion.Empty);

            // this is valid content
            content = "<Assembly: AssemblyVersion(\"1.3.0.*\")>\n";
            ais = new TestAssemblyInfoStream(content, "AssemblyInfo.vb");
            av = ais.GetVersions();
            Assert.IsTrue(av[AssemblyVersionType.AssemblyVersion] != ProjectVersion.Empty);
            Assert.IsTrue(av[AssemblyVersionType.AssemblyFileVersion] == ProjectVersion.Empty);
            Assert.IsTrue(av[AssemblyVersionType.AssemblyInformationalVersion] == ProjectVersion.Empty);

            // this is an invalid content
            content = "<Assembly: AssemblyVersion(\"a.b.c\")>\n";
            ais = new TestAssemblyInfoStream(content, "AssemblyInfo.vb");
            av = ais.GetVersions();
            Assert.IsTrue(av[AssemblyVersionType.AssemblyVersion] == ProjectVersion.Invalid);
            Assert.IsTrue(av[AssemblyVersionType.AssemblyVersion] == ProjectVersion.Empty);
            Assert.IsTrue(av[AssemblyVersionType.AssemblyFileVersion] == ProjectVersion.Empty);
            Assert.IsTrue(av[AssemblyVersionType.AssemblyInformationalVersion] == ProjectVersion.Empty);
        }
        */

        #region rc file content
        private const string rc1 =
            "// Microsoft Visual C++ generated resource script.\n" + 
            "//\n" + 
            "#include \"resource.h\"\n" + 
            "\n" + 
            "#define APSTUDIO_READONLY_SYMBOLS\n" + 
            "/////////////////////////////////////////////////////////////////////////////\n" + 
            "//\n" + 
            "// Generated from the TEXTINCLUDE 2 resource.\n" + 
            "//\n" + 
            "#define APSTUDIO_HIDDEN_SYMBOLS\n" + 
            "#include \"windows.h\"\n" + 
            "#undef APSTUDIO_HIDDEN_SYMBOLS\n" + 
            "\n" + 
            "/////////////////////////////////////////////////////////////////////////////\n" + 
            "#undef APSTUDIO_READONLY_SYMBOLS\n" + 
            "\n" + 
            "/////////////////////////////////////////////////////////////////////////////\n" + 
            "// Croatian resources\n" + 
            "\n" + 
            "#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_HRV)\n" + 
            "#ifdef _WIN32\n" + 
            "LANGUAGE LANG_CROATIAN, SUBLANG_DEFAULT\n" + 
            "#pragma code_page(1250)\n" + 
            "#endif //_WIN32\n" + 
            "\n" + 
            "/////////////////////////////////////////////////////////////////////////////\n" + 
            "//\n" + 
            "// Icon\n" + 
            "//\n" + 
            "\n" + 
            "// Icon with lowest ID value placed first to ensure application icon\n" + 
            "// remains consistent on all systems.\n" + 
            "IDI_WIN32APP            ICON                    \"Win32App.ico\"\n" + 
            "IDI_SMALL               ICON                    \"small.ico\"\n" + 
            "\n" + 
            "/////////////////////////////////////////////////////////////////////////////\n" + 
            "//\n" + 
            "// Menu\n" + 
            "//\n" + 
            "\n" + 
            "IDC_WIN32APP MENU \n" + 
            "BEGIN\n" + 
            "    POPUP \"&File\"\n" + 
            "    BEGIN\n" + 
            "        MENUITEM \"E&xit\",                       IDM_EXIT\n" + 
            "    END\n" + 
            "    POPUP \"&Help\"\n" + 
            "    BEGIN\n" + 
            "        MENUITEM \"&About ...\",                  IDM_ABOUT\n" + 
            "    END\n" + 
            "END\n" + 
            "\n" + 
            "\n" + 
            "/////////////////////////////////////////////////////////////////////////////\n" + 
            "//\n" + 
            "// Accelerator\n" + 
            "//\n" + 
            "\n" + 
            "IDC_WIN32APP ACCELERATORS \n" + 
            "BEGIN\n" + 
            "    \"?\",            IDM_ABOUT,              ASCII,  ALT\n" + 
            "    \"/\",            IDM_ABOUT,              ASCII,  ALT\n" + 
            "END\n" + 
            "\n" + 
            "\n" + 
            "/////////////////////////////////////////////////////////////////////////////\n" + 
            "//\n" + 
            "// Dialog\n" + 
            "//\n" + 
            "\n" + 
            "IDD_ABOUTBOX DIALOG  22, 17, 230, 75\n" + 
            "STYLE DS_SETFONT | DS_MODALFRAME | WS_CAPTION | WS_SYSMENU\n" + 
            "CAPTION \"About\"\n" + 
            "FONT 8, \"System\"\n" + 
            "BEGIN\n" + 
            "    ICON            IDI_WIN32APP,IDC_MYICON,14,9,16,16\n" + 
            "    LTEXT           \"Win32App Version 1.0\",IDC_STATIC,49,10,119,8,\n" + 
            "                    SS_NOPREFIX\n" + 
            "    LTEXT           \"Copyright (C) 2005\",IDC_STATIC,49,20,119,8\n" + 
            "    DEFPUSHBUTTON   \"OK\",IDOK,195,6,30,11,WS_GROUP\n" + 
            "END\n" + 
            "\n" + 
            "\n" + 
            "#ifdef APSTUDIO_INVOKED\n" + 
            "/////////////////////////////////////////////////////////////////////////////\n" + 
            "//\n" + 
            "// TEXTINCLUDE\n" + 
            "//\n" + 
            "\n" + 
            "1 TEXTINCLUDE \n" + 
            "BEGIN\n" + 
            "    \"resource.h\\0\"\n" + 
            "END\n" + 
            "\n" + 
            "2 TEXTINCLUDE \n" + 
            "BEGIN\n" + 
            "    \"#define APSTUDIO_HIDDEN_SYMBOLS\\r\\n\"\n" + 
            "    \"#include \"\"windows.h\"\"\\r\\n\"\n" + 
            "    \"#undef APSTUDIO_HIDDEN_SYMBOLS\\r\\n\"\n" + 
            "    \"\\0\"\n" + 
            "END\n" + 
            "\n" + 
            "3 TEXTINCLUDE \n" + 
            "BEGIN\n" + 
            "    \"\\r\\n\"\n" + 
            "    \"\\0\"\n" + 
            "END\n" + 
            "\n" + 
            "#endif    // APSTUDIO_INVOKED\n" + 
            "\n" + 
            "\n" + 
            "/////////////////////////////////////////////////////////////////////////////\n" + 
            "//\n" + 
            "// Version\n" + 
            "//\n" + 
            "\n" + 
            "VS_VERSION_INFO VERSIONINFO\n" + 
            " FILEVERSION 1,2,3,21\n" + 
            " PRODUCTVERSION 1,2,3,4\n" + 
            " FILEFLAGSMASK 0x17L\n" + 
            "#ifdef _DEBUG\n" + 
            " FILEFLAGS 0x1L\n" + 
            "#else\n" + 
            " FILEFLAGS 0x0L\n" + 
            "#endif\n" + 
            " FILEOS 0x4L\n" + 
            " FILETYPE 0x1L\n" + 
            " FILESUBTYPE 0x0L\n" + 
            "BEGIN\n" + 
            "    BLOCK \"StringFileInfo\"\n" + 
            "    BEGIN\n" + 
            "        BLOCK \"041a04b0\"\n" + 
            "        BEGIN\n" + 
            "            VALUE \"FileDescription\", \"Win32App Application\"\n" + 
            "            VALUE \"FileVersion\", \"1,2,3,21\"\n" + 
            "            VALUE \"InternalName\", \"Win32App\"\n" + 
            "            VALUE \"LegalCopyright\", \"Copyright (C) 2005\"\n" + 
            "            VALUE \"OriginalFilename\", \"Win32App.exe\"\n" + 
            "            VALUE \"ProductName\", \" Win32App Application\"\n" + 
            "            VALUE \"ProductVersion\", \"1,2,3,4\"\n" + 
            "        END\n" + 
            "    END\n" + 
            "    BLOCK \"VarFileInfo\"\n" + 
            "    BEGIN\n" + 
            "        VALUE \"Translation\", 0x41a, 1200\n" + 
            "    END\n" + 
            "END\n" + 
            "\n" + 
            "\n" + 
            "/////////////////////////////////////////////////////////////////////////////\n" + 
            "//\n" + 
            "// String Table\n" + 
            "//\n" + 
            "\n" + 
            "STRINGTABLE \n" + 
            "BEGIN\n" + 
            "    IDS_APP_TITLE           \"Win32App\"\n" + 
            "    IDC_WIN32APP            \"WIN32APP\"\n" + 
            "END\n" + 
            "\n" + 
            "#endif    // Croatian resources\n" + 
            "/////////////////////////////////////////////////////////////////////////////\n" + 
            "\n" + 
            "\n" + 
            "\n" + 
            "#ifndef APSTUDIO_INVOKED\n" + 
            "/////////////////////////////////////////////////////////////////////////////\n" + 
            "//\n" + 
            "// Generated from the TEXTINCLUDE 3 resource.\n" + 
            "//\n" + 
            "\n" + 
            "\n" + 
            "/////////////////////////////////////////////////////////////////////////////\n" + 
            "#endif    // not APSTUDIO_INVOKED\n" + 
            "\n";

        #endregion // rc file content
    }
}
